package mornd.bootstart;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author: mornd
 * @dateTime: 2023/5/24 - 15:01
 */
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.equals("user")) {
            System.out.println("BeanPostProcessor#before");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.equals("user")) {
            System.out.println("BeanPostProcessor#after");
            // 模拟 aop
            User user = new User();
            user.setName("李四");
            return user;
        }
        return bean;
    }
}
